/**
 * @Description:
 * @author 紫霞
 * @since 2019/1/17
 */
// React基础组件
import React from 'react'
// dva 连接组件 - 连接route和model
import { connect } from 'dva'
// 引入antd的组件
import {
  message,
  Form,
  Row,
  Col,
  Input,
  Cascader,
  Tag,
  Icon,
  DatePicker,
  Select,
  Button,
  Upload,
  Modal,
  Divider,
  Checkbox,
  Radio,
  Popconfirm,
} from 'antd'

const FormItem = Form.Item
const { TextArea } = Input
//导入路由组件，用于跳转等
import { Link, hashHistory } from 'dva/router'
// 导入项目全局配置文件
import config from 'config/config'
import { isEmpty, get, merge,cloneDeep } from 'lodash'
// 引入model取值工具方法
import { mapStateToProps } from 'utils/view_utils'
//引用listPage
import ListPage from 'widget/PageTmpl/ListPage'
import cx from 'classnames'
import { Grid, QueryCondition } from 'widget/Grid/index'
import { AdvanceSearch } from 'widget/CollapsiblePanels/index'

import Uploader from '../../../../widget/Upload'
import Ueditor from '../../../../widget/Editor/Ueditor.js'

// 当前组件样式
import styles from './activityDetailStyle.less'
import { CollapsiblePanels } from 'widget/CollapsiblePanels/index'
import moment from 'moment/moment'
import PopUpSelectnoModal from 'widget/PopUpSelectnoModal/PopUpSelect'
import PopUpSelect from 'widget/PopUpOne/PopUpSelect'
/**
 * description 路由视图及事件处理
 * dispatch 分发到models中的effects对应事件名
 * model 用于获取models中state定义的数据
 * form 表单对象
 */
const formItemLayout = {
  labelCol: {span: 6},
  wrapperCol: {span: 15},
}
const imageLayout = {
  labelCol: {span: 3},
  wrapperCol: {span: 24},
}
const imageLayout1 = {
  labelCol: {span: 4},
  wrapperCol: {span: 24},
}
const formItemLayout2 = {
  labelCol: {span: 8},
  wrapperCol: {span: 14},
}
const { RangePicker, } = DatePicker

let productTypeMap = {//商品类型
  1:'房源',
  2:'停车位',
  3:'商铺',
  4:'日用快消',
  5:'家电数码',
  6:'首饰箱包',
  7:'其他',
}
let propertyTypeMap={//物业类型
  11:'住宅',
  12:'公寓',
  21:'地上车位',
  22:'地下车位（非人防车位',
  23:'地下车位（人防车位）',
  24:'地下车库',
  25:'地上车库',
  31:'地上商铺',
  32:'地下商铺',
  33:'地上集中商业',
  34:'地下集中商业',
}

function includes (item,arr) {
  let flag=false
  if(arr.indexOf(item+'')>-1){
    flag=true
  }
  return flag
}

const sellerTableColumn = [
  {title: '项目名称', dataIndex: 'projectName', key: 'projectName',width:120,},
  {title: '商品名称', dataIndex: 'detail', key: 'detail'},
  {title: '所属城市', dataIndex: 'provinceName', key: 'provinceName',width:100,render:(text,record,index)=>{
    let arr = ['北京市','重庆','上海','天津']
      if(arr.indexOf(text)>-1){
        return text
      }else{
        return  <span>{`${text}${text && '-'}${record.cityName}`}</span>
      }
  }}
];
const sellerTablenoModalColumn = [
  {title: '项目名称', dataIndex: 'name', key: 'name',width:120,},
  {title: '所属城市', dataIndex: 'provinceName', key: 'provinceName',width:100,render:(text,item,index)=>{
    let arr = ['北京市','重庆','上海','天津']
      if(arr.indexOf(item.provinceName)>-1){
          return `${item.cityName}${item.provinceName&&item.cityName&&item.countyName&&' - '||''}${item.countyName||''}`
        }else{
          return `${item.provinceName||''}${item.provinceName&&item.cityName&&' - '||''}${item.cityName||''}${item.provinceName&&item.cityName&&item.countyName&&' - '||''}${item.countyName||''}`
        }
    }
}
];
const sellerSelectednoModalColumn = [
  {title: '项目名称', dataIndex: 'name', key: 'name',width:120,},
  {title: '所属城市', dataIndex: 'provinceName', key: 'provinceName',render:(text,item,index)=>{
    let arr = ['北京市','重庆','上海','天津']
    if(arr.indexOf(item.provinceName)>-1){
        return `${item.cityName}${item.provinceName&&item.cityName&&item.countyName&&' - '||''}${item.countyName||''}`
      }else{
        return `${item.provinceName||''}${item.provinceName&&item.cityName&&' - '||''}${item.cityName||''}${item.provinceName&&item.cityName&&item.countyName&&' - '||''}${item.countyName||''}`
      }
  }
   
}
];
let timer=null
function runTimer (cbk) {
  if(!timer){
    timer=setInterval(()=>{cbk()},1000)
  }else{
    clearInterval(timer)
    timer=setInterval(()=>{cbk()},1000)
  }
}
const routeView = function ({dispatch, model, form}) {
  // 表单的子函数
  const {resetFields, getFieldDecorator, validateFields, setFieldsValue} = form
  // 取出model对象，命名空间
  const {modelObj, namespace} = model

  // modelObj.xxx获取model中状态机的值
  // let {id,pageType,detailInfo, formData, imageUrls, modalObj,tableData, pageConfig,loading,onItem,} = modelObj
  let {id,pageType,detailInfo,detailBanner,gif, 
      accountItem={},local,
      formData,imgStyle,productIds, imageUrls,areaList,selectItem,
      gifimg,visible, activityDetail={},tableModalData, 
      modalObj,tableData, pageConfig,loading,onItem,designatedVisible,addressList,currentItem,isSubmit,timerVisible,date,timerItem} = modelObj
      console.log(addressList,'addressList')
  let sellerQueryList = [
    {name: '区域公司', type: 'select', key: 'regionId',list:addressList,notNeedAll:true},
    { name: '省市', type: 'cascader', list: cloneDeep(areaList), key: ['province', 'city', 'county'], value: '' },
    { name: '项目名称', type: 'text', key: 'name', value: '' },
  ];
  console.log('modelObj==',modelObj)
  const sellerSelectedColumn = [
    {title: '项目名称', dataIndex: 'projectName', key: 'projectName',width:120},
    {title: '兑奖方式', dataIndex: 'receiveWay', key: 'receiveWay',width:120,
      render:(text,record,index)=>{
        return <Radio.Group onChange={(e) => {
          if(onItem.length > 0){
            for(let i=0;i<onItem.length;i++){
              if(onItem[i].seckillProductId == record.seckillProductId){
                onItem[i].receiveWay = e.target.value;
                break;
              }
            }
            changeState({onItem});
          }
        }}>
          <Radio value={1}>项目现场兑奖</Radio>
          <Radio value={2}>邮寄</Radio>
        </Radio.Group>
      }
    },
    {title: '商品名称', dataIndex: 'detail', key: 'detail'},
    {title: '所属城市', dataIndex: 'provinceName', key: 'provinceName',width:100,render:(text,record,index)=>{
      let arr = ['北京市','重庆','上海','天津']
      if(arr.indexOf(text)>-1){
        return text
      }else{
        return  <span>{`${text}${text && '-'}${record.cityName}`}</span>
      }
    }}
  ];
  //计时器遍历，判断是否显示‘出价‘按钮
  runTimer(() => {
    if (!includes(detailInfo.published, ['2'])) {
      return false
    }
    // console.log('runTimer...')
    let flag = false//是否需要刷新数据
    tableData.dataSource.map((item, index) => {//year month week day hour minute second
      // console.log('',includes(item.status, ['2']),(!item.showBidding), (moment().isAfter(item.startTime,'minute')),(moment().isBefore(item.endTime,'minute')))
      if (includes(item.status, ['2']) && (!item.showBidding) &&  moment().isAfter(item.startTime,'minute') && moment().isBefore(item.endTime,'minute')) {//进入竞拍时间
        // debugger
        tableData.dataSource[index].showBidding = true
        flag = true
      }
    })
    if (flag) {changeState({tableData})}
  })
  
  
  // 表格配置------------开始
  // 序号
  
  // 竞拍商品 商品类型 竞拍时间 起拍价 竞拍幅度 报名费 定金
  // 序号  秒杀商品 name  商品类型 productType  秒杀时间 startTime endTime   原价 originalPrice  秒杀价 seckillPrice 应付报名费 securityMoney  应付定金  earnestMoney
  const columns = [
    {
      title: '序号', dataIndex: 'key', key: 'key', width: 60,render: function (value, item, index) {
        return index + 1
      }
    },
    {title: '兑奖方式', dataIndex: 'receiveWay', key: 'receiveWay',render:function (value,item,index) {
      return <div>
          <FormItem {...formItemLayout}
                      label="">
                        {getFieldDecorator(`receiveWay_${index}`, {
                  initialValue: value,
                  rules: [
                  ],
                  // normalize: normalize
                })(
                  <Radio.Group 
                    // disabled={formData.needEnroll==2}
                    onChange={e =>{
                      changeReceiveWay(e.target.value, 'receiveWay',item)
                    }} >
                    <Radio value={'1'}>项目现场兑奖</Radio>
                    <Radio value={'2'}>邮寄</Radio>
                  </Radio.Group>
                )}
              
            </FormItem>
      </div>
      }
    },
    {title: '竞拍被超发送短信给竞拍者', dataIndex: 'noticeFlag', key: 'noticeFlag',render:function (value,item,index) {
      return <div>
          <FormItem {...formItemLayout}
                      label="">
                        {getFieldDecorator(`noticeFlag_${index}`, {
                  initialValue: value,
                  rules: [
                  ],
                  // normalize: normalize
                })(
                  <Radio.Group 
                    // disabled={formData.needEnroll==2}
                    onChange={e =>{
                      changeNoticeFlag(e.target.value, 'noticeFlag',item)
                    }} >
                    <Radio value={0}>不发送</Radio>
                    <Radio value={1}>发送</Radio>
                  </Radio.Group>
                )}
              
            </FormItem>
      </div>
      }
    },
    {title: '竞拍商品', dataIndex: 'name', key: 'name',width:270},
    {title: '商品类型', dataIndex: 'productType', key: 'productType',width:100,
      render:function (value,item) {
        return <span>{productTypeMap[value]||''}</span>
      }
    },
    {
      title: '竞拍时间', dataIndex: 'startTime', key: 'startTime',width:330,
      render: function (value, item) {
        let time =`${item.startTime||''}${item.endTime&&' ~ '||''}${item.endTime||''}`
        return <span>{time}</span>
      }
    },
    {title: '起拍价', dataIndex: 'initPrice', key: 'initPrice'},
    {title: '竞拍幅度', dataIndex: 'grads', key: 'grads'},
    {title: '报名费', dataIndex: 'securityMoney', key: 'securityMoney'},
    {title: '定金', dataIndex: 'earnestMoney', key: 'earnestMoney'},
  ]
  const gridProps = {
    nameSpace: namespace,
    data: {
      columns: [].concat(columns, generateAction()),//已发布的活动不能添加和删除时间段
      pageConfig, tableData,
    },
    pageChange: (pageNo, pageSize) => {
      console.log(pageNo, pageSize)
      dispatch({ type: `${namespace}/pageChange`, payload: {pageNo, pageSize } });
    },
    scroll: {x: 1300},
    loading
  }

  const modalGridProps = {
    nameSpace: namespace,
    selectedKeysChange:'selectedKeysChange',
    data: {
      columns: [{title: '竞拍商品', dataIndex: 'name', key: 'name'},],
      pageConfig:modalObj.pageConfig,
      tableData:modalObj.tableData,
      selectedRowKeys:modalObj.selectedRowKeys,
    },
    pageChange: (pageNo, pageSize) => {
      console.log(pageNo, pageSize)
      dispatch({ type: `${namespace}/pageChangeModal`, payload: {pageNo, pageSize } });
    },
    scroll: {x: 1000},
    loading
  }

  // 表格操作区域
  function generateAction () {
    return {
      title: '操作',
      key: 'operation',
      fixed: 'right',
      width: 120,
      render: (data, record, index) => {
        var t1 = moment()
        var t2 = record.startTime
        var t3=record.endTime
        return (
          moment(t3).isBefore(t1)?null
          // <span style={{color:"#ccc"}}>删除</span>
          :
          <span>
            {((pageType == 'edit') && includes(detailInfo.published,['1','2']))&&
            <Popconfirm Collapse title={`确定要删除吗？`}  okText='确定' cancelText='取消' onConfirm={() =>deleteItem(record)}>
              <a href='javascript:void(0)' onClick={(e) => {
                // 阻止事件冒泡
                // e.stopPropagation();
              }}>删除
              </a>
              {<span className="ant-divider" />}
                </Popconfirm>
            }
            
            {record.showBidding&&
              <a  onClick={() => routerGo({ type: 'bidding', item: record })}>出价</a>
            }
            {<span className="ant-divider" />}
                <a href='javascript:void(0)' onClick={(e) => {
                  timeModal(true,record)
                }
                }>修改时间
                  </a>
          </span>
        )
      }
    }
  }
  //解除时间关联
  function deleteItem (item={}) {
    dispatch({
      type:`${namespace}/relieveTimeSlot`,
      payload:{
        ...item
      }
    })
  }
  // 更新商品状态 发布、撤销 发布状态	published（1，未发布。2，已发布，3已撤销）
  function updatePublished (newType) {
    if(newType==2&&pageType!="detail"){
          save(newType)
        }else{
          dispatch({
            type:`${namespace}/updatePublished`,
            payload:{
              newType:newType
            }
          })
        }
    // validateFields((err,values) => {
    //   if (err) {
    //     for(var i in err){
    //       message.error(err[i].errors[0].message)
    //   }
    //     return false
    //   } else {
    //     if(newType==2&&pageType!="detail"){
    //       save(newType)
    //     }else{
    //       dispatch({
    //         type:`${namespace}/updatePublished`,
    //         payload:{
    //           newType:newType
    //         }
    //       })
    //     }
    //   }
    // })
    
  }

  
  //修改状态
  const changeState = (payload) => {
    dispatch({
      type: `${namespace}/updateStore`,
      payload: {...payload}
    })
  }
  //表单输入
  function inputChange (value, key) {
    formData[key] = value
    changeState({formData: formData})
  }
  
  //领取方式
  function changeReceiveWay(value, key,item){
    let {seckillActivityId,seckillProductId,endTime,startTime,noticeFlag} = item
    let seckillProductList = [];
    let seckillMap = {
      productId:seckillProductId,
      receiveWay:value,noticeFlag
    };
    seckillProductList.push(seckillMap);
    let params = {
      seckillActivityId,
      seckillProductList,
      sellType:2,
      endTime:endTime,
      startTime:startTime
    }
    console.log(params);
    dispatch({
      type: `${namespace}/createTimeSlot`,
      payload: {params}
    })
  }
  //是否发送短信给竞拍者
  function changeNoticeFlag(value,key,item){
    let {seckillActivityId,seckillProductId,endTime,startTime,receiveWay} = item
    let seckillProductList = [];
    let seckillMap = {
      productId:seckillProductId,
      noticeFlag:value,receiveWay
    };
    seckillProductList.push(seckillMap);
    let params = {
      seckillActivityId,
      seckillProductList,
      sellType:2,
      endTime:endTime,
      startTime:startTime
    }
    console.log(params);
    dispatch({
      type: `${namespace}/createTimeSlot`,
      payload: {params}
    })
  }

  function timeModal(visible,item){
    // console.log(item)
    let date = {}
    if(item){
      date = {
        startTime:item.startTime,
        endTime:item.endTime
      }
    }
    
    dispatch({ type: `${namespace}/updateStore`, payload: { timerVisible:visible,date,timerItem:item||{}}});
  }
  //date改变时
  function dateChange(dates, dateString,type) {
    if(type=='showDate'){
      formData['showStartTime'] = dateString[0]
      formData['showEndTime'] = dateString[1]
      dispatch({
        type: `${namespace}/updateStore`,
        payload: { formData }
      });
    }else{
      date['startTime'] = dateString[0]
      date['endTime'] = dateString[1]
      dispatch({
        type: `${namespace}/updateStore `,
        payload: { date }
      });
    }
    
    
  }

  // 详情页跳转
  function routerGo ({type = '', item={}}) {
    let urlArray = MODULE_TO_ROUTES[namespace].urlArray
    let pathname =urlArray[0]
    
   if(type=='bidding'){
     pathname = urlArray[2]
     id=item.seckillProductId
   }
    hashHistory.push({
      pathname:pathname,
      query: {
        pageType: type,
        id: id,
      }
    })
  }

  // 详情页跳转
  function save (type) {
    // e.preventDefault();
    // 校验参数 validateFields中数组规则：添加表单校验必须添加到该数组中
    validateFields(['name','imageUrls','showDate','detailBanner'],(err) => {
      if (err) {
        return false;
      }
      if(pageType=='add'){
        dispatch({
          type: `${namespace}/create`,
          payload: {}
        })
      }else if(pageType=='edit'){
        dispatch({
          type: `${namespace}/update`,
          payload: {resetFields,type}
        })
      }
      dispatch({
        type: `${namespace}/updateStore`,
        payload: {btnLoading:true}
      })

    });

  }
  
  function updateImageModel(value,key='imageUrls') {
    let arr
    if( key =='imageUrls'){
      modelObj[key].push(value)
    } else {
      //arr = value
      // 分发到model
      modelObj[key] = value
      dispatch({
        type: `${namespace}/updateStore`,
        payload: { [key]:value }
      })
    }
  };
  
  
  function removeImgUrl(index,key='imageUrls') {
    if(pageType=='detail'){
      return false
    }
    let val 
    if(key=='imageUrls'){
      imageUrls.splice(index, 1)
    }else{
      val = undefined
      resetFields([key])
      dispatch({
        type: `${namespace}/updateStore`,
        payload: { [key]:val}
      })
    }
  }
  
  function range(start, end) {
    const result = [];
    for (let i = Number(start); i < Number(end); i++) {
      result.push(i);
    }
    return result;
  }
  
  function disabledDate(current) {
    // Can not select days before today and today
    return current && (moment(current).format("YYYY-MM-DD") < moment().add('days',3).format("YYYY-MM-DD"));
  }
  
  
  
  function confirmCbk(onItem=[]) {
    // e.preventDefault(e);
    changeState({onItem})
    if(isEmpty(onItem)){
      updateModal()
      return false
    }else{
      for(let i=0;i<onItem.length;i++){
        if(!onItem[i].receiveWay){
          message.error("请先选择兑奖方式");
          return false;
        }
      }
    }
    validateFields(['newTime'],(err) => {
      if (err) {
        return false
      } else {
        modalObj.visible=false
        changeState({modalObj})
        onItem.map(item =>{
          item.noticeFlag = 0
        })
        console.log(onItem);
        debugger
        dispatch({
          type: `${namespace}/createTimeSlot`,
          payload: {onItem}
        })
      }
    })
  }
  
  function onChange (onItem=[]) {
    console.log('onChange',onItem)
    changeState({onItem:onItem})
  }
  // 弹窗
  function updateModal () {
    modalObj.visible = !modalObj.visible
    if(modalObj.visible){
      resetFields(['newTime'])
      formData.newTime=null
      onItem=[]
    }
    changeState({modalObj,formData,onItem})
  }
   //获取动态图
   function getGif(e) {       
    gifimg = e.target.value
    dispatch({
        type: `${namespace}/updateStore`,
        payload: { gifimg }
    })
  }
  //随机选择动态图片
  function random() {
    let  i = Math.floor(Math.random() * 6)
        while(1){
            if(gifimg==gif[i]){
                i = Math.floor(Math.random() * 6)
            }else{
                break;
            } 
        }  
    console.log(gif[i])
    gifimg = gif[i]
    dispatch({
        type: `${namespace}/updateStore`,
        payload: { gifimg }
    });
  }
  //是否选择本地图片
  function onChangeTolocal() {
    dispatch({
        type: `${namespace}/updateStore`,
        payload: { local: !local }
    });
  }
  return (
    <div className={cx('public_listMain')}>
      <div className="functionButton">
        {
          (pageType == 'add' || pageType == 'edit')  &&
          <Button type="primary" loading={modelObj.btnLoading} onClick={(e) => {save()}}>保存</Button>
        }
        {
          (pageType == 'detail') &&includes(detailInfo.published,['1',]) &&
          <Button type="primary" onClick={() => {routerGo({type: 'edit'})}}>编辑</Button>
        }
        {//published {1:'未发布',2:'已发布',3:'已撤销',}
          pageType == 'detail' && formData.published == 2 &&
          <Button type="primary" loading={modalObj.publishLoading} onClick={() => {updatePublished(3)}}>撤销</Button>
        }
        {
          (pageType == 'detail' || pageType == 'edit') &&includes(detailInfo.published,['1']) &&
          <Button type="primary" loading={modalObj.publishLoading} onClick={() => {updatePublished(2)}}>发布</Button>
        }
        {
          pageType != 'add' &&includes(detailInfo.published,['2']) &&
          <Button type="primary" loading={modalObj.publishLoading} onClick={() => {updatePublished(4)}}>取消发布</Button>
        }
          

      </div>

      <CollapsiblePanels title="竞拍活动管理" hideUpDownBtn={true}>
        <Form>
          <Row>
            <Col className="col" span={6}>
              <FormItem {...formItemLayout}
                label="活动名">
                {getFieldDecorator('name', {
                  initialValue: formData.name,
                  rules: [
                    { required: true, message: '方案最多14个字', max: 14 }
                  ],
                })(<Input
                  disabled={(pageType == "detail") ||includes(detailInfo.published,['2'])? true : false}
                  placeholder={'方案最多14个字'}
                  onChange={(e) => { inputChange(e.target.value, 'name') }}
                />)}
              </FormItem>
            </Col>
            {pageType == 'detail' &&
              <Col className="col" span={6} style={{ 'lineHeight': '40px' }}>
                活动状态：{{ 1: '未发布', 2: '已发布', 3: '已撤销', }[formData.published]}
              </Col>}
          </Row>
          <Row>
            <FormItem {...imageLayout1}
            className='leftlabel'
                      label="【活动页面】活动主题图">
              {getFieldDecorator('imageUrls', {
                initialValue: imageUrls,
                rules: [
                  { required: true,message: '请上传【活动页面】活动主题图' }
                ],
              })(<div>
                {
                   (pageType == "detail"||includes(detailInfo.published,['2'])) ? <div>
                      {
                        imageUrls && imageUrls.map((x,i)=>{
                          return <img style={{width:100,height:100,padding:10}}  key = {i} src={x} alt=""/>
                        })
                      }
                    </div>:
                    <Uploader uploadedUrls ={imageUrls}
                              removeFileCbf={(index)=>{removeImgUrl(index)}}
                              uploadSuccessCbf={ (imgUrl) => {updateImageModel(imgUrl)} }
                              showType={pageType == 'detail'?'4':"6"}
                              fileType='image'
                              fileMaxSize='0.5'
                              minCropBoxWidth={1500}
                              minCropBoxHeight={800}
                              unsetWidth={true}
                              maxFiles='10' />
                }
              </div>)}
            </FormItem>

            <Col span={12}>
              <span style={{ color: '#999', marginLeft: '4%' }}>
              图片分辨率需为1500px*800px，且文件大小在500kb以下，支持jpg，png格式。
                  </span>
            </Col>
          </Row>

          <Row>
              <Col span={18}>
                <FormItem 
                    {...formItemLayout2}
                    label='在福利、美房详情显示活动入口的时间'>
                    {getFieldDecorator('showDate', {
                      initialValue: formData.showStartTime ? [moment(formData.showStartTime), moment(formData.showEndTime)] : [],
                      rules: [
                        { required: true, message: '请选择显示日期' },
                      ],
                    })(<RangePicker
                      style={{ minWidth: 185, width: "100%" }}
                      format="YYYY-MM-DD HH:mm:ss"
                      // locale={locale}
                      showTime
                      // disabled={actionType == 'detail'}
                      onChange={(showDate, dateString) => dateChange(showDate, dateString,'showDate')} />)}
                  </FormItem>
              </Col>
          </Row>
        <FormItem
          {...imageLayout1}
          className='leftlabel'
          extra="图片分辨率需为1372px*672px，且文件大小在500kb以下，支持jpg，png格式。"
          label="【楼盘主页】活动主题图"
          required='true'>
            {getFieldDecorator('detailBanner', {
                initialValue: detailBanner,
                rules: [
                  { required: true,message: '请上传【楼盘主页】活动主题图' }
                ],
              })(
                <div>
                  <Uploader uploadedUrls={detailBanner}
                    removeFileCbf={() => { removeImgUrl(1,'detailBanner') }}
                    uploadSuccessCbf={(detailBanner) => { 
                      console.log(detailBanner)
                      updateImageModel(detailBanner, 'detailBanner') 
                      // form.resetFields['img']
                    }}
                    showType={pageType == 'detail'?'4':"6"}
                    minCropBoxWidth={1372}
                    minCropBoxHeight={672}
                    unsetWidth={true}
                    fileType='image'
                    fileMaxSize='0.5'
                    maxFiles='1'     
                    /> 
                </div>
              )}
          
                        </FormItem>
                        <span style={{color: "#666",fontSize: "12px"}}>预览图:</span>
                        <div className={styles.box} style={{marginTop: '10px'}}>
                            
                            <div className={styles.preview}>
                                {<div>
                                   { detailBanner ? <img src={detailBanner} style={{ 'width': '117px', 'height': '68px' }} alt="" />
                                       : null}
                                    {/* {gifimg && !imgStyle?<img src={gifimg} style={{ 'width': '40px', 'height': '40px', 'position': 'absolute', 'right': '6px', 'top': '16px' }} alt="" />:null}  */}
                                </div>
                                }
                            </div>
                            {/* <div style={{ 'width': '110px', 'marginLeft': '20px' }}>
                                {
                                    pageType == 'detail' ? null :
                                        <div>
                                            <Button type='primary' disabled={imgStyle} onClick={() => { random() }}>随机换动态图</Button>
                                            <Button type='primary' disabled={imgStyle} style={{ 'marginTop': '10px' }} onClick={() => {
                                                dispatch({
                                                    type: `${namespace}/updateStore`,
                                                    payload: { visible: true }
                                                })
                                            }}>手动更换</Button>
                                            <Checkbox onChange={e => { 
                                              dispatch({
                                                type: `${namespace}/updateStore`,
                                                payload: { imgStyle: e.target.checked }
                                              })
                                            }} checked={imgStyle} style={{ 'marginTop': '10px' }}>不使用动态图</Checkbox>
                                        </div>
                                }
                            </div> */}
                        </div>
                        </Form>
        <Modal
                width='60%'
                title="选择默认动态图"
                onOk={() => {
                    dispatch({
                        type: `${namespace}/updateStore`,
                        payload: { visible: false }
                    })
                }}
                visible={visible && pageType != 'detail'}
                onCancel={() => {
                    dispatch({
                        type: `${namespace}/updateStore`,
                        payload: { visible: false }
                    })
                }}
            >
                {pageType == 'detail' ? null :
                    <div style={{ "width": "100%" }}>
                        <div className={styles.box}>
                            <div className={styles.preview}>
                                {
                                    detailBanner ? <img src={detailBanner} style={{ 'width': '343px', 'height': '71px' }} alt="" />
                                        : <div style={{ 'fontSize': '20px', 'color': 'blue', 'lineHeight': '71px', 'textAlign': 'center' }}>未上传活动图</div>
                                }
                                <img src={gifimg} style={{ 'width': '40px', 'height': '40px', 'position': 'absolute', 'right': '6px', 'top': '16px' }} alt="" />
                            </div>
                        </div>

                        <Radio.Group style={{ 'marginTop': '20px' }} onChange={e => { getGif(e) }} defaultValue={gifimg}>

                            {!local ? <Row >
                                <Col span={4}>
                                    <Uploader uploadedUrls={gifimg}
                                        removeFileCbf={() => { removeImgUrl(1,'gifimg') }}
                                        uploadSuccessCbf={(imgUrl) => { updateImageModel(imgUrl, 'gifimg') }}
                                        showType={pageType == 'detail'?'4':"3"}
                                        minCropBoxWidth={176}
                                        minCropBoxHeight={176}
                                        fileMaxSize='0.05'
                                        maxFiles='1'
                                        disabled={local}
                                    />
                                </Col>
                                <Col span={16}>
                                    <span>图片分辨率需为176px*176px，且文件大小在50kb以下，支持jpg，png格式。</span>
                                </Col>

                            </Row> : null}
                            <Checkbox onChange={onChangeTolocal}>本地图片</Checkbox>
                            <div style={{ 'marginTop': '20px' }}>
                                <Row>
                                    <Col span={8}>
                                        <img src={gif[0]} style={{ 'width': '100px', 'height': '100px' }} alt="" />    <div className={cx('center')}><Radio value={gif[0]} disabled={!local}>选择</Radio></div>

                                    </Col>
                                    <Col span={8}>
                                        <img src={gif[1]} style={{ 'width': '100px', 'height': '100px' }} alt="" />    <div className={cx('center')}><Radio value={gif[1]} disabled={!local}>选择</Radio></div>

                                    </Col>
                                    <Col span={8}>
                                        <img src={gif[2]} style={{ 'width': '100px', 'height': '100px' }} alt="" />    <div className={cx('center')}><Radio value={gif[2]} disabled={!local}>选择</Radio></div>

                                    </Col>

                                </Row>
                                <Row style={{ 'marginTop': '40px' }}>
                                    <Col span={8}>
                                        <img src={gif[3]} style={{ 'width': '100px', 'height': '100px' }} alt="" />     <div className={cx('center')}><Radio value={gif[3]} disabled={!local}>选择</Radio></div>

                                    </Col>
                                    <Col span={8}>
                                        <img src={gif[4]} style={{ 'width': '100px', 'height': '100px' }} alt="" />
                                        <div className={cx('center')}><Radio value={gif[4]} disabled={!local}>选择</Radio></div>
                                    </Col>
                                    <Col span={8}>
                                        <img src={gif[5]} style={{ 'width': '100px', 'height': '100px' }} alt="" />    <div className={cx('center')}><Radio value={gif[5]} disabled={!local}>选择</Radio></div>

                                    </Col>

                                </Row>
                            </div>

                        </Radio.Group>
                        <div>

                        </div>
                    </div>
                }
            </Modal>              
      </CollapsiblePanels>
      {
        <CollapsiblePanels title="适用楼盘" hideUpDownBtn={true}>
           <PopUpSelectnoModal
                    tableColumn={sellerTablenoModalColumn}
                    selectedColumn={sellerSelectednoModalColumn}
                    selectedTableScroll={{ x: 420 }}
                    queryList={cloneDeep(sellerQueryList)}
                    isSave={true}
                    refreshByEnter={true}
                    requestUrl='admin/estate/adminList'
                    title='选择工程名称'
                    respListKey='rows'
                    idKey='productId'
                    onItem={selectItem}
                    onChange={(e) => {
                        let ids=[]
                        e.map((item)=>{
                          ids.push(item.productId)
                        })
                        productIds=Array.from(new Set(ids))
                        dispatch({
                            type: `${namespace}/updateStore`,
                            payload: {productIds,selectItem:e}
                        })
                    }}
                ></PopUpSelectnoModal>
        </CollapsiblePanels>
      }
      {//pageType!=='add'&&

        <CollapsiblePanels title="活动时间段" hideUpDownBtn={true}>
          <div className={cx('clearfix')}>
          {/* {console.log(detailInfo,'detailInfo',!((pageType == 'edit') && includes(detailInfo.published,['1','2',])))} */}
          <Button type='primary' className={cx('fr')} 
          disabled={!((pageType == 'edit') && includes(detailInfo.published,['1','2'])) ? true : false}
          // disabled={pageType == 'detail'}
              onClick={() => { updateModal() }}>添加竞拍商品</Button>
          </div>

          <div className={'mgt1'}>
            <Grid {...gridProps} />
          </div>
        </CollapsiblePanels>
      }

        <CollapsiblePanels title="配置竞拍规则" hideUpDownBtn={true}>
        <div>
          <FormItem {...{labelCol:{span:2},wrapperCol:{span:22}}}>
            <Ueditor id="activityDetail"
              style={{ width: '100%', height: 900 }}
              // editable={actionType === 'detail' ? false : true}
              html={detailInfo.ruleDesc || ''}
              title={detailInfo.title || ''}
              startDate={detailInfo.startDate || ''}
              endDate={detailInfo.endDate || ''}
              height={500}
              isSubmit={isSubmit}
              inputChange={e => {
                dispatch({ type: `${namespace}/dealEditor`, payload: { detail: e } })
              }}
              isSubmit={
                e => { dispatch({ type: `${namespace}/updateStore`, payload: { isSubmit: e.isSubmit } }) }
              }
            />
          </FormItem>
          
        </div>
       
      </CollapsiblePanels>
      {pageType !== 'add' &&
        <CollapsiblePanels title="活动创建信息" hideUpDownBtn={true}>
          <Row>
            <Col className="col" span={6}>创建人：{formData.createPerson}</Col>
            <Col className="col" span={6}>创建时间：{formData.createTime}</Col>
          </Row>
        </CollapsiblePanels>
      }
      <PopUpSelect
        tableColumn={sellerTableColumn}
        selectedColumn={sellerSelectedColumn}
        selectedTableScroll={{ x: 420 }}
        visible={modalObj.visible}
        closeCbk={e => updateModal()}
        confirmCbk={(onItem) =>{
          confirmCbk(onItem)
        }}
        onChange={onChange}
        isSave={true}
        // isSingle={false}
        onItem={onItem||[]}
        requestUrl={`admin/seckill/queryProductByType?sellType=${modelObj.sellType}`}
        method={'get'}
        title='添加商品'
        respListKey='rows'
        idKey = 'seckillProductId'
        layout={[{span:12},{span:12}]}
        slot={<Form className="public_listMain">
          <Row>
            <Col span={12}>
              <FormItem label={'竞拍时间'} {...formItemLayout}>
                {
                  getFieldDecorator('newTime', {
                    rules: [
                      { required: true, type: 'array', message: `请选择时间` },
                    ],
                    initialValue: formData.newTime||null
                  })
                  (<RangePicker style={{width: '100%'}}
                                placeholder={['开始时间', '结束时间']}
                                allowClear={false}
                                format="YYYY-MM-DD HH:mm"
                                onChange={(dates, dateStrings) => {
                                  formData.newTime=dates;
                                  changeState({formData})
                                }}
                                // disabledDate={disabledDate}
                                // disabledTime={disabledRangeTime}
                                showTime={{
                                  hideDisabledOptions: true,
                                  format: 'HH:mm',
                                }}/>)
                }
              </FormItem>
            </Col>
          </Row>
        </Form>}
      />

      <Modal title={'修改商品时间'}
             visible={timerVisible}
             okText={'确认'}
             cancelText={'取消'}
             onCancel={(e) => {
               timeModal(false)
             }}
             onOk={(e) => {
              let {seckillActivityId,seckillProductId,receiveWay} = timerItem
              let seckillProductList = [];
              let seckillMap = {
                productId:seckillProductId,
                receiveWay
              };
              seckillProductList.push(seckillMap);
              let params = {
                seckillActivityId,
                seckillProductList,
                sellType:1,
                endTime:date.endTime,
                startTime:date.startTime
              }
              dispatch({
                type: `${namespace}/createTimeSlot`,
                payload: {params}
              })
              timeModal(false)
             }}
             width={720}
             destroyOnClose={true}
             >
               <FormItem
                    label='商品时间'>
                    {getFieldDecorator('date', {
                      initialValue: date.startTime ? [moment(date.startTime), moment(date.endTime)] : null,
                      rules: [
                        { required: false, type: 'array', whitespace: true, message: '请选择商品日期' },
                      ],
                    })(<RangePicker
                      style={{ minWidth: 185, width: "100%" }}
                      format="YYYY-MM-DD HH:mm:ss"
                      // locale={locale}
                      showTime
                      // disabled={actionType == 'detail'}
                      onChange={(date, dateString) => dateChange(date, dateString)} />)}
                  </FormItem>
        </Modal>
      
    </div>
  )
}

// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(routeView))
